//
//  MineZhiFuViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/25.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "MineZhiFuViewController.h"
#import "MineZhiFuTableViewCell.h"
@interface MineZhiFuViewController ()<UITableViewDelegate, UITableViewDataSource>

{

    NSString *acquiescence;//设置选中状态
    
    
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *buttonOfSure;
@property (nonatomic, strong) NSMutableDictionary *dataDic;


@end

@implementation MineZhiFuViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    [self regeditCell];
    [self creationData];
    // Do any additional setup after loading the view.
}
- (void)creationView{

    [self setTitle:@"支付"];
    UIView *viewOf = [[UIView alloc] init];
    viewOf.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 1);
    [self.view addSubview:viewOf];
    viewOf.backgroundColor = [UIColor colorWithRed:204 / 255.0f green:204 / 255.0f  blue:204 / 255.0f  alpha:1];
    
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 - 44);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //   self.tableView.estimatedRowHeight = 400;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    
    
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];

    self.buttonOfSure = [[UIButton alloc] init];
    [self.view addSubview:self.buttonOfSure];
    [self.buttonOfSure mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(44);
        
    }];
    
//    254 212 54
    self.buttonOfSure.backgroundColor = [UIColor colorWithRed:254 / 255.0f green:212 / 255.0f blue:54 / 255.0f alpha:1];
    [self.buttonOfSure setTitle:@"确认支付400币" forState:UIControlStateNormal];
    [self.buttonOfSure setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
    
    
    
}
- (void)regeditCell{
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineZhiFuTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineZhiFuTableViewCell"];
    
    
    
}
- (void)creationData{
    
    _dataDic = [[NSMutableDictionary alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
//    [productParams setValue:self.orderId forKey:@"orderId"];
    [productParams setValue:@"161" forKey:@"orderId"];
    [[MNetworkHandler sharedInstance]conURL:adminorderPaymentUserMoney networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            self.dataDic = [returnData objectForKey:@"data"];
            
            
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}

#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"3"]) {
        
        return 3;
    }else {
    
        return 2;
        
    }
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 60;
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    MineZhiFuTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MineZhiFuTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    if ([[self.dataDic objectForKey:@"type"] isEqualToString:@"3"]) {
        if (indexPath.row == 0) {
            cell.nameLabel.text = [self.dataDic objectForKey:@"money_jiaoyi_name"];
            cell.money.text = [self.dataDic objectForKey:@"money_jiaoyi"];
        }else if (indexPath.row ==1){
        
            cell.nameLabel.text = [self.dataDic objectForKey:@"money_shangcheng_new_name"];
            cell.money.text = [self.dataDic objectForKey:@"money_shangcheng_new"];
            
        }else if (indexPath.row ==2){
            
            cell.nameLabel.text = [self.dataDic objectForKey:@"money_lvyou_name"];
            cell.money.text = [self.dataDic objectForKey:@"money_lvyou"];
            
        }
    }else {
    
        if (indexPath.row == 0) {
            cell.nameLabel.text = [self.dataDic objectForKey:@"money_shangcheng_new_name"];
            cell.money.text = [self.dataDic objectForKey:@"money_shangcheng_new"];
        }else{
            
            cell.nameLabel.text = [self.dataDic objectForKey:@"money_lvyou_name"];
            cell.money.text = [self.dataDic objectForKey:@"money_lvyou"];
            
        }
        
    }
    
    
    
    return cell;
    
    
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

 
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
